<?php
include '../common.php';
$rule = [
		'username' => ['kong','名称不能为空'],
	 	'email'    => ['kong','邮箱不能为空'],
	 	'email'    => ['is_email','邮箱格式不正确'],
	 	'code'    => ['kong','验证码不能为空'],
];
$a = panduan($rule);
if($a['code'] == 0){
	exit($a['msg']);
}

$username = trim($_POST['username']);
$email    = trim($_POST['email']);
$code     = trim($_POST['code']);

if ($code !== $_SESSION['code']) {
	unset($_SESSION['code']);
	exit('验证码不正确');
}
unset($_SESSION['code']);

$sql  = "SELECT * FROM public_user WHERE name = '{$username}'";
$row = select($sql,$DB);
if (!$row) {
	exit('用户名不存在');
}

if (trim($row[0]['email']) !== $email) {
	exit('邮箱错误');
}
setcookie("username",$username, time()+60,'/');
setcookie("email",$email, time()+60,'/');

header("location:../forget.php?forget=1",302);